package com.ruoyi.wlxz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wlxz.domain.WxzSuggest;
import com.ruoyi.wlxz.service.IWxzSuggestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 建议箱Controller,暂时没用上,以后也不一定会用
 * 
 * @author zlh
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/wlxz/suggest")
public class WxzSuggestController extends BaseController
{
    @Autowired
    private IWxzSuggestService wxzSuggestService;

    /**
     * 查询建议箱列表
     */
    @PreAuthorize("@ss.hasPermi('wlxz:suggest:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxzSuggest wxzSuggest)
    {
        startPage();
        List<WxzSuggest> list = wxzSuggestService.selectWxzSuggestList(wxzSuggest);
        return getDataTable(list);
    }

    /**
     * 导出建议箱列表
     */
    @PreAuthorize("@ss.hasPermi('wlxz:suggest:export')")
    @Log(title = "建议箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxzSuggest wxzSuggest)
    {
        List<WxzSuggest> list = wxzSuggestService.selectWxzSuggestList(wxzSuggest);
        ExcelUtil<WxzSuggest> util = new ExcelUtil<WxzSuggest>(WxzSuggest.class);
        util.exportExcel(response, list, "建议箱数据");
    }

    /**
     * 获取建议箱详细信息
     */
    @PreAuthorize("@ss.hasPermi('wlxz:suggest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxzSuggestService.selectWxzSuggestById(id));
    }

    /**
     * 新增建议箱
     */
    @PreAuthorize("@ss.hasPermi('wlxz:suggest:add')")
    @Log(title = "建议箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxzSuggest wxzSuggest)
    {
        wxzSuggest.setAccept(3L);
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserId();
        wxzSuggest.setUserId(userId);
        return toAjax(wxzSuggestService.insertWxzSuggest(wxzSuggest));
    }

    /**
     * 修改建议箱
     */
    @PreAuthorize("@ss.hasPermi('wlxz:suggest:edit')")
    @Log(title = "建议箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxzSuggest wxzSuggest)
    {
        return toAjax(wxzSuggestService.updateWxzSuggest(wxzSuggest));
    }

    /**
     * 删除建议箱
     */
    @PreAuthorize("@ss.hasPermi('wlxz:suggest:remove')")
    @Log(title = "建议箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxzSuggestService.deleteWxzSuggestByIds(ids));
    }
}
